using System;
using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;
using Guard=Common.Core.Guard;

namespace Common.Unity.Extensions.Configuration
{
	public class PolicyInjection : InjectionMember
	{
		readonly Type policyType;

		public PolicyInjection( Type policyType, IBuilderPolicy policy )
		{
			Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull( policyType, "policyType" );
			Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull( policy, "policy" );
			Guard.IsOfType( typeof(IBuilderPolicy), policyType );
			this.policyType = policyType;
			this.policy = policy;
		}

		public IBuilderPolicy Policy
		{
			get { return policy; }
		}	readonly IBuilderPolicy policy;

		public override void AddPolicies( Type typeToCreate, string name, IPolicyList policies )
		{
			policies.Set( policyType, policy, new NamedTypeBuildKey( typeToCreate, name ) );
		}
	}
}